package com.skh.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: skh
 * @Date: 2019/6/18 16:32
 * @Description:
 */
public class ThreadTest {
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("执行run方法");
                try {
                    Thread.sleep(223);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        new Thread(runnable).start();

        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("执行callable方法");
                Thread.sleep(2000);
                return 10;
            }
        };

        FutureTask<Integer> futureTask = new FutureTask(callable);
        new Thread(futureTask).start();

        try {
            Integer integer = futureTask.get();
            System.out.println("integer = " + integer);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }
}
